//
//  LeftViewController.m
//  QuanZiChat
//
//  Created by lanou3g on 15/11/24.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "LeftViewController.h"
#import "JZLoginViewController.h"
#import "JZMenuViewController.h"
#import "PersonalMessageViewController.h"
@interface LeftViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *fotterView;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;//头像
@property (weak, nonatomic) IBOutlet UILabel *nickName;//昵称
@property (weak, nonatomic) IBOutlet UILabel *individualitySignature;//个性签名
@property (weak, nonatomic) IBOutlet UIImageView *qrCode;//二维码
@property (weak, nonatomic) IBOutlet UIView *headView;//头部视图




@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addGestureRecognizer];
    
    
    
    // Do any additional setup after loading the view.
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
 
    //-----------------------------------------------//
    AVFile *file = [[AVUser currentUser] objectForKey:@"headImage"];
    
    
    [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        
        self.headImageView.image = [UIImage imageWithData:data];
        
        
        
    } progressBlock:^(NSInteger percentDone) {
        
        NSLog(@"%ld", percentDone);
    }];
    
    AVFile *file1 = [[AVUser currentUser] objectForKey:@"QRCodeImage"];
    
    
    [file1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        
        self.qrCode.image = [UIImage imageWithData:data];
        
        
        
    } progressBlock:^(NSInteger percentDone) {
        
        NSLog(@"%ld", percentDone);
    }];

    
    //-----------------------------------------------//
  
   
    AVUser *currentUser = [AVUser currentUser];
    
    self.nickName.text = [currentUser objectForKey:@"nickName"];
    self.individualitySignature.text = [currentUser objectForKey:@"IndividualitySignature"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//添加手势
-(void)addGestureRecognizer{
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    
    //手势添加到视图
    [self.headView addGestureRecognizer:tapGesture];
    self.headView.userInteractionEnabled = YES;
}

-(void)tapGestureAction:(UITapGestureRecognizer *)tapGesture{
    
    PersonalMessageViewController *personalMessageVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PersonalMessageViewController"];
    
    [self presentViewController:personalMessageVC animated:YES completion:nil];
    
}

//退出当前账号
- (IBAction)cancleLogin:(id)sender {
    
    [AVUser logOut];  //清除缓存用户对象
    //AVUser *user = [AVUser currentUser];
    

    UIStoryboard *login = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    JZLoginViewController *loginVC = [login instantiateViewControllerWithIdentifier:@"JZLoginViewController"];
    [self presentViewController:loginVC animated:YES completion:nil];
}



#pragma mark - Delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.textLabel.text = @"测试";
    return cell;
    
}

//分区尾
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *fotterview = [[UIView alloc] init];
    
    fotterview = self.fotterView;
    
    fotterview.backgroundColor = [UIColor blueColor];
    
    
    
    return fotterview;
}

//尾视图高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 100;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
